{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "inputfile=r'C:\\Users\\Administrator\\Desktop\\HWSD土壤数据库终极版.xlsx'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=pd.read_excel(inputfile,skiprows=1,na_values=0)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in df.index:\n",
    "    if(pd.isnull(df.loc[i]['TEXTURE'])):\n",
    "        for j in df.index:\n",
    "            if((df.loc[j]['T_CLAY']==df.loc[i]['T_CLAY'])&(df.loc[j]['T_SILT']==df.loc[i]['T_SILT'])&(pd.isnull(df.loc[j]['TEXTURE']!=1))&(df.loc[j]['S_CLAY']==df.loc[i]['S_CLAY'])):\n",
    "                df.loc[i]=df.loc[j]\n",
    "                break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_excel(excel_writer=r'C:\\Users\\Administrator\\Desktop\\hwsd\\hwsd.xlsx',sheet_name='HWSD',index=False,header=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list=df['SU_SYM90'].value_counts().index\n",
    "name_list=list(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.index=range(len(df.index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "condition1=(df.loc[j]['T_CLAY']==df.loc[i]['T_CLAY'])\n",
    "condition2=(df.loc[j]['T_SILT']==df.loc[i]['T_SILT'])\n",
    "condition3=(pd.isnull(df.loc[j]['TEXTURE']!=1))\n",
    "condition4=(df.loc[j]['S_CLAY']==df.loc[i]['S_CLAY'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[j]['T_CLAY']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "condition4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "if((df.loc[j]['T_CLAY']==df.loc[i]['T_CLAY'])&(df.loc[j]['T_SILT']==df.loc[i]['T_SILT'])&(pd.isnull(df.loc[j]['TEXTURE']!=1))&(df.loc[j]['S_CLAY']==df.loc[i]['S_CLAY'])):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "df.loc[7001]['T_CLAY']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[7002]['T_CLAY']==df.loc[7001]['T_CLAY']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "for i in df.index:\n",
    "    if(pd.isnull(df.loc[i]['TEXTURE'])):\n",
    "        for j in df.index:\n",
    "            if((df.loc[j]['T_CLAY']==df.loc[i]['T_CLAY'])&(df.loc[j]['T_SILT']==df.loc[i]['T_SILT'])&(pd.isnull(df.loc[j]['TEXTURE']!=1))&(df.loc[j]['S_CLAY']==df.loc[i]['S_CLAY'])):\n",
    "                df.loc[i]=df.loc[j]\n",
    "                break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[7001]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[7002]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.isnull(df.loc[7001]['TEXTURE'])!=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "exist_name_list="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(list(name_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['SU_SYM90'].value_counts().index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "len(df['SU_SYM90'].value_counts().index)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
